package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.GridView;

import com.example.myapplication.adapter.GridAdapter;

public class GridViewDemoActivity extends AppCompatActivity {
    //①
    private GridView gridView;//创建GridView对象

    String[] names = new String[]{"播放器","电话","短信",
            "联系人","设置","手机防盗","关闭","微信","照相机"};

    int[] icons = new int[]{R.drawable.widget01,R.drawable.widget02,
            R.drawable.widget03,R.drawable.widget04, R.drawable.widget05,
            R.drawable.widget06,R.drawable.widget07,
            R.drawable.widget08,R.drawable.widget09};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_grid_view_demo);

        gridView = findViewById(R.id.grid_view);//绑定对应的组件或者找到组件

        //②选择对应的适配器

        //实例化定义好的适配器
        GridAdapter adapter = new GridAdapter(this,R.layout.grid_item,names,icons);

        //讲实例化的对象，放到对应的组件中
        gridView.setAdapter(adapter);

//        gridView.setAdapter();
    }
}